<template>
  <el-container>
    <el-header>
      <el-carousel :interval="4000" type="card" height="200px" style="margin-top: 9%;">
        <el-carousel-item v-for="(item, i) in imgList" :key="i">
          <img width="100%" height="100%" :src="item.url" />
        </el-carousel-item>
      </el-carousel>
    </el-header>
    <el-container>
      <el-aside width="200px">
        <div class="aside-content">
          <h2>正在热映</h2>
  <el-row>
          <el-col
            v-for="(elem, index) in showingFilmListRowOne"
            :key="index"
           :offset="index &gt; 0 ? 1 : 0">
            <el-card shadow="never" :body-style="{ padding: '0px' }">
             
              <img class="movieImg"
                :src="elem.filmPicture"
              />      
               <div class="movie_sale">
           
                   <router-link :to="{name:'cinema',query:{filmInfo:JSON.stringify(elem)}}">购票</router-link>
                
              
              </div>

            </el-card> 
           
            <div class="movie_info">
                <div class="movie_title">{{elem.filmName}}</div>
                <div class="movie_score">{{elem.filmScore}}</div>
            </div>
            
          </el-col>
            </el-row>
            <el-row style="margin-top:20px">
          <el-col
            v-for="(elem, index) in showingFilmListRowTwo"
            :key="index"
           :offset="index &gt; 0 ? 1 : 0">
            <el-card shadow="never" :body-style="{ padding: '0px' }">
             
              <img class="movieImg"
                :src="elem.filmPicture"
              />      
               <div class="movie_sale">
           
                   <router-link :to="{name:'cinema',query:{filmInfo:JSON.stringify(elem)}}">购票</router-link>
                
              
              </div>

            </el-card> 
           
           <div class="movie_info">
                <div class="movie_title">{{elem.filmName}}</div>
                <div class="movie_score">{{elem.filmScore}}</div>
            </div>
            
          </el-col>
            </el-row>
            <h2 class="notice">即将上映</h2>
               <el-row>
          <el-col
            v-for="(elem, index) in ToBEShownFilmList"
            :key="index"
           :offset="index &gt; 0 ? 1 : 0">
            <el-card shadow="never" :body-style="{ padding: '0px' }">
             
              <img class="movieImg"
                :src="elem.filmPicture"
              />      
               <div class="movie_sale">
           
                   <router-link :to="{name:'cinema',query:{filmInfo:JSON.stringify(elem)}}">购票</router-link>
                
              
              </div>

            </el-card> 
           
            <div class="movie_info">
                <div class="movie_title">{{elem.filmName}}</div>
                <div class="movie_score">{{elem.filmScore}}</div>
            </div>
            
          </el-col>
            </el-row>
         
        </div>
      </el-aside>
      <el-main>
        <div style="width:466px">
               <h2 class="coming_soon">
          梓晨公告
        </h2>
        <span @click="whole" style="float:right;margin-top:25px;color:red;cursor:pointer">全部></span>
        </div>
   
        <div class="notice_wrapper"  v-for="item in noticeList" :key="item.noticeId">
          <div class="notice_content">
            <router-link :to="{path:'/notice/notice/',query:{id:item.noticeId}}">{{
              item.noticeTitle
            }}</router-link>
            
            </div>
          <label style="float:right">{{item.noticeTime}}</label>
            <el-divider></el-divider>
          </div>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      avatarUrl:
        "https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png",
      searchContent: "",
      activeIndex: "/index",
      imgList: [
        { url: require("../assets/image/1.jpg") },
        { url: require("../assets/image/2.jpg") },
        { url: require("../assets/image/3.jpg") },
      ],
      showingFilmListRowOne: [],
      showingFilmListRowTwo: [],
      ToBEShownFilmList: [],
      noticeList:[]
    };
  },
  created() {
    this.getMovieList();
    this.getNoticeList();
  },
  methods: {
    async getMovieList() {
      const { data: res } = await this.$http.post("/common/filminfo/getList",{});
      console.log(res);
      if (res.code != 200) {
        return this.$message.error(res.message);
      } else {
        var temp = res.data.value;
        temp.forEach((element,i) => {
          if (element.filmStatus == "上映") {
            if(this.showingFilmListRowOne.length < 3){
              this.showingFilmListRowOne.push(element);
            }
            else if(this.showingFilmListRowTwo.length < 3){
              this.showingFilmListRowTwo.push(element);
            }
            
          } else if (element.filmStatus == "待上映") {
            if(this.ToBEShownFilmList.length < 3){
                this.ToBEShownFilmList.push(element);
            }
            
          }
        });
      }
    },
    async getNoticeList(){
        const{data:res} = await this.$http.get("/common/notice/notice/getNoticeList")
        if(res.code != 200){
         console.log("获取公告列表失败")
        }
        else{
          let length = res.data.length
          length = length > 3 ? 3 : length
          this.noticeList = res.data.slice(0,length)
        }

    },
    //点击全部公告
    whole(){
      this.$router.push('/notice')
    }
  },
};
</script>

<style lang="less" scoped>
#container {
  height: 100%;
  .el-menu-item {
    font-size: 20px;
    margin-top: 19px;
    font-family: Microsoft YaHei, Helvetica, Arial, sans-serif;
  }
}
.el-container {
  height: 100%;
}
.el-header {
  height: auto !important;
}
.el-aside {
  width: 65% !important;
  height: 100%;
  overflow: unset;
}
.el-main {
  height: 100%;
  overflow: unset;
  .notice_wrapper{
    width: 470px;
    font-size: 14px;
      a{
        text-decoration: none;
        color:#000;
        
    }
  }
  .notice_content{
     white-space: nowrap;
     text-overflow: ellipsis;
     overflow: hidden;
    width: 265px;
    display: inline-block;
  }
}
   h2 {
  font-size: 26px;
  font-weight: 400;
  color: red;
  margin-bottom: 20px;
}
.el-menu {
  height: 100%;
  display: inline-block;
}
.logo {
  width: 152px;
  height: 100%;
  margin-right: 10px;
}
.search {
  width: 200px;
  top: -42px;
  left: 64px;
  .el-input__icon {
    cursor: pointer;
  }
}
.el-avatar {
  float: right;
  margin-top: 20px;
}
.el-carousel {
  width: 100%;
  //   height: 450px;
}

.aside-content {
  margin: 0 auto;
  // width: 865px;

  h2 {
  font-size: 26px;
  font-weight: 400;
  color: red;
  margin-bottom: 20px;
}
h4{
    color: red;
    font-weight: 400;
    margin-right: 0;
    display: inline-block;
        margin-right: 118px;
        float: right;
  }
}
.el-card {
  width: 200px;
  height: 332px;
  font-size: 0;
}
.movieImg {
  width: 100%;
  height: 286.1px;
}
.movie_info {
  width: 100%;
  color: #fff;
  position: absolute;
  bottom: 57px;
  overflow: hidden;
}
.movie_title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0 10px;
  float: left;
}
.movie_score {
  color: #ffb400;
  float: right;
  margin-right: 7px;
}
.el-col {
  position: relative;
  width: 22%;
}
.coming_soon,.notice {
  margin-top: 20px;
  display: inline-block;
}
.movie_sale {
  text-align: center;
  height: 46px;
  line-height: 46px;
  text-decoration: none;
  background: #fff;
  font-size: 16px;

  a {
    display: block;
    width: 100%;
    height: 100%;
    text-decoration: none;
  }
  a:hover {
    background-color: #ef4238;
    color: #fff;
  }
}
.el-divider--horizontal {
    margin: 11px 0;
}
.el-carousel_container{
  margin-top: 9%;
}
</style>